<!doctype html>
<html class="no-js fixed-layout">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>首页</title>
  <meta name="description" content="index">
  <meta name="keywords" content="index">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="/static/assets/i/favicon.png">
  <link rel="apple-touch-icon-precomposed" href="/static/assets/i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="/static/assets/css/amazeui.min.css"/>
  <link rel="stylesheet" href="/static/assets/css/admin.css">
  <style type="text/css">
    .input_width{
      width: 200px;
    }
  </style>
</head>
<body>



  <div class="admin-content">
    <div class="admin-content-body">

      <div class="am-g">


 
        <div class="am-u-sm-12 am-u-md-12 ">
          <!--中间侧块 注意下面是form表-->
          
          <div class="am-form-group">

            
            <hr/>
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-sm-5 am-u-md-6 am-text-right">检修单位：</div>
              <div class="am-u-sm-7 am-u-md-4 am-u-end" style="padding-left: 0px;">
                
                <select  id='organize_id' name='organize_id' class="input_width" required=""  onchange="change()">
                  {% for i in deptInfo %}
                  {% if i.organize_id == loginInfo.0.organize_id %}
                  <option value={{ i.organize_id  }} selected="selected" >{{ i.name }}</option>
                  {% else %}
                  <option value={{ i.organize_id }} >{{ i.name }}</option> 
                  {% endif %}
                  {% endfor %}
                </select>
              </div>

            </div>
            <hr/>
            <div class="am-g am-margin-top am-form-group" id="bridge_csbm" >
              <div class="am-u-sm-5 am-u-md-6 am-text-right">责任人：</div>
              <div class="am-u-sm-7 am-u-md-4 am-u-end" style="padding-left: 0px;">
                <select  id='user_id' name='user_id' class="input_width" required="">
                  {% for i in userInfo %}
                  {% if i.user_id == loginInfo.0.user_id %}
                  <option value={{ i.user_id }} selected="selected">{{ i.real_name }}</option> 
                  {% else %}
                  <option value={{ i.user_id }} >{{ i.real_name }}</option>
                  {% endif %}
                  {% endfor %}
                </select>
              </div>

            </div>
            <hr/>
            <div class="am-g am-margin-top am-form-group" id="bridge_csbm" >
              <div class="am-u-sm-5 am-u-md-6 am-text-right">检查开始时间：</div>
              <div class="am-u-sm-7 am-u-md-4 am-u-end" style="padding-left: 0px;">
                <input type="date" class="input_width" id="start_time"/>
              </div>

            </div>
            <hr/>
             <div class="am-g am-margin-top am-form-group" id="bridge_csbm" >
              <div class="am-u-sm-5 am-u-md-6 am-text-right">检查结束时间：</div>
              <div class="am-u-sm-7 am-u-md-4 am-u-end" style="padding-left: 0px;">
                <input type="date" class="input_width" id="end_time"/>
              </div>

            </div>
         
            <hr/>
           

          </div>
          
        </div>
        <div class="am-u-sm-12 am-u-md-6">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs" style="padding: 0 280px;">

              <button type="button" class="am-btn am-btn-primary am-btn-xs" onclick="add_submit({{ tp }},{{ check_id }})">保存</button>


            </div>
          </div>
        </div>

      </div>
    </div>

  </div>



<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/static/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/static/assets/js/amazeui.min.js"></script>
<script src="/static/assets/js/amazeui.tree.js"></script>
<script src="/static/assets/datatables/amazeui.datatables.min.js"></script>
<script src="/static/assets/dialog/amazeui.dialog.min.js"></script>
<script type="text/javascript" src="/static/assets/js/layer.js"></script>
<link rel="stylesheet" type="text/css" href="/static/assets/css/amazeui.tree.css" />
<script src="/static/assets/js/app.js"></script>
<script type="text/javascript">

  var tp = 0;
  var tp = {{ tp|safe }};
  var tp = {{ tp|safe }};
$.ajaxSetup({
  data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
});
$(document).ready(function(){
  var date = new Date();
    var seperator1 = "-";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
   
  $("#start_time").attr('value',currentdate);
  $("#end_time").attr('value',currentdate); 
})
 

function add_submit(type,check_id){
  var organize_id = $("#organize_id option:selected").val();
  var name = $("#organize_id option:selected").text();
  var user_id = $("#user_id option:selected").val();
  var real_name = $("#user_id option:selected").text();
  var start_time = $("#start_time").val();
  var end_time = $("#end_time").val(); 
  if(organize_id==''){
    AlertMSG("请选择检修单位！")
  }else if(user_id==''){
    AlertMSG("请选择责任人！")
  }else if(start_time==''){
    AlertMSG("请选择检查开始时间！")
  }else if(end_time==''){
    AlertMSG("请选择检查结束时间！")
  }else if(end_time<start_time){
    AlertMSG("结束时间早于开始时间，请重新输入！")
  }else {
    $.ajax({
      "url":"/JDXJ_JJDJ_ADDSAVE/",
      "data":{"name":name,"real_name":real_name,"start_time":start_time,"end_time":end_time,"user_id":user_id,"organize_id":organize_id,"tp":type,"check_id":check_id},
      "datatype":"json",
      "type":"post",
      "async":"false"
      }).success(function(data){
        if (data.status == 1) {
          message_layer(data.message)
          var index = parent.layer.getFrameIndex(window.name);
          parent.location.reload();
          parent.layer.close(index);


        } else {
          AlertMSG(data.message)
        }
      }).error(function(data){
        AlertMSG("保存失败！")
      });
  }
}

// message_layer(data.message)
function message_layer(message){
    layer.msg(message, {
    time: 2000 //2秒关闭（如果不配置，默认是3秒）
  }); 
}

function change(){
  var organize_id = $("#organize_id option:selected").val();

  $.ajax({
      "url":"/JDXJ_RCXC_XCJL_USER/?organize_id="+organize_id+"",
      "datatype":"json",
      "type":"get",
      "async":"false"
      }).success(function(data){
        if (data.status == 1) {
          $("#user_id").empty();
          for(var i=0;i<data.data.length;i++){
            $('#user_id').append('<option value='+data.data[i].user_id+' >'+data.data[i].real_name+'</option>');
          }

    

        } else {
          AlertMSG(data.message)
        }
      }).error(function(data){
        AlertMSG("读取负责人失败！")
      });
}

var AlertMSG=function(msg){
    AMUI.dialog.alert({ title: '错误提示', content: msg, onConfirm: function() { console.log('close'); } });
}
</script>
</body>

</html>